package com.example.mvpdemo.main;

import android.content.Intent;
import android.os.Bundle;
import android.os.CountDownTimer;
import android.support.annotation.Nullable;
import android.support.v7.app.AppCompatActivity;
import android.view.WindowManager;

import com.example.mvpdemo.R;
import com.example.mvpdemo.login.view.LoginActivity;
import com.example.mvpdemo.utils.Constant;
import com.example.mvpdemo.utils.SpUtils;


public class SplashActivity extends AppCompatActivity {

    private CountDownTimer mTimer;

    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        getWindow().addFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN);//隐藏状态栏
        setContentView(R.layout.activity_splash);
        initData();
    }



    public void initData() {
        /**
         * CountDownTimer 3秒后跳转登录页面
         *
         */
        int first = SpUtils.getInt(Constant.FIRST,-1);
        if (first == -1){
            mTimer = new CountDownTimer(3*1000,1000) {
                @Override
                public void onTick(long millisUntilFinished) {
                }

                @Override
                public void onFinish() {
                    toLogin(GuideActivity.class);
                }
            }.start();
        }else {
            toLogin(LoginActivity.class);
        }

    }

    private void toLogin(Class<?> cls){
        Intent intent = new Intent(SplashActivity.this, cls);
        startActivity(intent);
        finish();
    }

}
